package org.vectrics.common.html;

import org.apache.ecs.html.Select;
import org.apache.ecs.html.Option;
import java.util.Enumeration;
import org.apache.ecs.Element;
import org.apache.log4j.Logger;

public class Combo extends Select {

	private static final long serialVersionUID = -6540472192267316054L;
	protected Logger log = Logger.getLogger(this.getClass());
	
    public Combo() {
        setName("unnamed_select");
    }

    public Option addOption(String iDesc, String iID)
    {
        Option option = new Option();
        option.setValue(iID);
        option.addElement(iDesc);

        this.addElement(option);
        return(option);
    };
    
    public void selectOption(String iID) {
        Option selectElement = null;
        Enumeration elements = this.elements();
        while ((elements.hasMoreElements()) && (selectElement == null)) {
            Element child = (Element)elements.nextElement();
            if (child.getClass() == Option.class) {
                Option option = (Option)child;
                if (option.getAttribute("value").equals(iID)) {
                    selectElement = option;
                    selectElement.setSelected(true);
                }
            };
        }
    };

}
